	.text

/* Switch from current_thread to next_thread. Make next_thread
 * the current_thread, and set next_thread to 0.
 * Use eax as a temporary register; it is caller saved.
 */
	.globl thread_switch
thread_switch:
	/* YOUR CODE HERE */
	 # 保存当前线程的寄存器
    push %ebp
    push %ebx
    push %esi
    push %edi

    # 保存当前栈指针到current_thread->sp
    movl current_thread, %eax
    movl %esp, (%eax)

    # 恢复下一个线程的栈指针
    movl next_thread, %eax
    movl (%eax), %esp

    # 恢复下一个线程的寄存器
    pop %edi
    pop %esi
    pop %ebx
    pop %ebp

    # 更新current_thread和清除next_thread
    movl next_thread, %eax
    movl %eax, current_thread
    movl $0, next_thread

    ret
